//
//  FeedbackViewController.m
//  Housekeeping
//
//  Created by 辰领科技 on 16/5/26.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "FeedbackViewController.h"

@interface FeedbackViewController ()
<UITextViewDelegate>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UIButton *confirmButton;
@property (strong, nonatomic) IBOutlet UILabel *feedbackLabel;
@property (strong, nonatomic) IBOutlet UITextView *feedbackTextView;
@property (strong, nonatomic) IBOutlet UITextField *contactWayTextField;
@property (strong, nonatomic) IBOutlet UIButton *button;



@end

@implementation FeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
}

- (void)initViewLayout {
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    self.scroview.contentSize = flexibleSize(CGSizeMake(320, 504.5), YES);
    
    _button.layer.cornerRadius = 21*VerticalRatio();
    
    self.feedbackTextView.layer.borderColor = [UIColor colorWithRed:192/255.0 green:192/255.0 blue:192/255.0 alpha:1].CGColor;
    self.feedbackTextView.layer.borderWidth = 1;
    self.feedbackTextView.layer.cornerRadius = 10;
    self.contactWayTextField.layer.borderColor = [UIColor colorWithRed:192/255.0 green:192/255.0 blue:192/255.0 alpha:1].CGColor;
    self.contactWayTextField.layer.borderWidth = 1;
    self.contactWayTextField.layer.cornerRadius = 10;
    self.contactWayTextField.leftViewMode = UITextFieldViewModeAlways;
    self.contactWayTextField.leftView = [[UIView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 5, 10), NO)];
    
    self.feedbackTextView.delegate = self;
}







#pragma mark - 确认
- (IBAction)confirm:(id)sender {
    
    if ([Common dataIsNULL:self.feedbackTextView.text]) {
        [CWHUDTips showTips:@"请输入您的意见反馈"];
        return;
    }
    if ([Common dataIsNULL:self.contactWayTextField.text]) {
        [CWHUDTips showTips:@"请输入您的联系方式"];
        return;
    }

    
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:self.feedbackTextView.text forKey:@"content"];
    [dic setObject:self.contactWayTextField.text forKey:@"email"];
    [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"member"];
    [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    [dic setObject:[Common getLoginInfo][Key_User_Phone] forKey:@"phone"];
    [dic setObject:@"2" forKey:@"devicetype"];
    
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:HK_userFeedbackinfo withHttpType:@"POST" withTag:HK_HK_userFeedbackinfo];
}

#pragma mark - 返回
- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - <UITextViewDelegate>


- (void)textViewDidChange:(UITextView *)textView{

        if (self.feedbackTextView.text.length > 0) {
            self.feedbackLabel.hidden = YES;
        }else{
            self.feedbackLabel.hidden = NO;
        }
        
}





#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag == HK_HK_userFeedbackinfo){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        }else  {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [[Common getNavigation]popViewController];
        }
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
